package com.tim.helper.project;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.util.Arrays;
import java.util.Locale;

/**
 * @author
 * @Title:
 * @Package
 * @date 2022/12/3 11:47
 * @Description:
 */
public class BaoFuHelper {
    @Test
    public void genBaoFuReq() throws NoSuchFieldException {
    String str =
        "域名\t变量名\t必填\t字段类型\t备注\n"
            + "protocolNo\tprotocolNo\tM\tString\t此字段已不用\n"
            + "签约协议号\tagreementNo\tM\tString\t\n"
            + "持卡人姓名\tcardUserName\tM\tString\t\n"
            + "卡号后4位\tlastCardNo\tM\tString\t\n"
            + "银行预留手机号\tbankMobile\tM\tString\t\n"
            + "银行编号\tbankCode\tM\tString\t见下表银行编号\n"
            + "银行名称\tbankName\tM\tString\t见下表银行编号\n"
            + "银行卡类型\tcardType\tM\tString\t1-借记卡 2-信用卡\n"
            + "银行联行号\tcnapsCode\tM\tString\t\n"
            + "是否对公\tpublicFlag\tM\tString\tY:对公账户；N: 对私账户\n"
            + "还款日期\trepaymentDate\tM\tString\t\n"
            + "主卡标识（默认的）\tmainFlag\tM\tString\t\n"
            + "状态\tstatus\tM\tString\t\n"
            + "可用标识\tavaFlag\tM\tString\t\n"
            + "备注\tremark\tM\tString";
        String template = "/**\n*%1$s\t%3$s\n*%5$s\n*/\nprivate %4$s %2$s;\n\n";
        str = str.replaceAll("\t\n", "\t \n")
                .replaceAll("\t$", "\t ")
                .replaceAll("\tDate\t", "\tString\t");
    Arrays.stream(str.split("\n"))
        .filter(StringUtils::isNotBlank)
        .skip(1)
        .forEach(
            e -> {
              String[] strs = e.split("\t");
              if (strs.length < 5) {
                System.out.println(strs[0]);
              }else{
                  System.out.println(String.format(template, strs));
              }
            });
    }

    @Test
    public void genBaoFuReqJson() throws NoSuchFieldException {
        String str = "域名\t变量名\t必填\t字段类型\t备注\n" +
                "机构号/平台号\torgNo\tM\tString\t宝付提供（同商户号）\n" +
                "终端号\tterminalNo\tM\tString\t宝付提供\n" +
                "登录号\tloginNo\tM\tString\t用户登录注册号，为用户在商户下唯一编号，商户自定义\n" +
                "请求日期\trequestDate\tM\tString\t发起请求时的服务器时间yyyyMMddHHmmss\n" +
                "申请邮箱\temail\tM\tString\t用于接收注册邮件\n" +
                "法人是否实际控制人\tinControl\tM\tInteger\t0-否 1-是\n" +
                "受益人是否实际控制人\tinBenefit\tM\tInteger\t0-否 1-是\n" +
                "填写人是否法人\tproposer\tM\tInteger\t0-否 1-是\n" +
                "企业名称\tmerchantName\tM\tString\t企业名称\n" +
                "企业地址\tmerchantAddress\tM\tString\t企业地址\n" +
                "社会信用代码\tregNo\tM\tString\t社会信用代码\n" +
                "注册资本\tregCapital\tM\tInteger\t注册资本(单位：元)\n" +
                "法人姓名\tcorporateName\tM\tString\t\n" +
                "法人身份证号\tcorporateIdCard\tM\tString\t\n" +
                "联系人手机号\tcontactMobile\tM\tString\t\n" +
                "开户名称\tcardName\tM\tString\t\n" +
                "开户银行\tbankName\tM\tString\t\n" +
                "开户银行所在省\tprovinceName\tM\tString\t\n" +
                "开户银行所在市\tcityName\tM\tString\t\n" +
                "开户银行支行名称\tbranchName\tM\tString\t\n" +
                "企业对公账号\tcardNo\tM\tString\t\n" +
                "经营范围\tbusinessScope\tM\tString\t\n" +
                "代理人姓名\tagentName\tC\tString\tproposer为0时填写\n" +
                "代理人身份证号\tagentIdCard\tC\tString\tproposer为0时填写\n" +
                "受益人类型\tbeneficiaryType\tC\tInteger\tinBenefit为0时填写;0-个人 1-企业\n" +
                "受益人归属地\tbeneficiaryArea\tC\tString\tbeneficiaryType为0时填写\n" +
                "受益人姓名\tbeneficiaryName\tC\tString\tbeneficiaryType为0时填写\n" +
                "受益人身份证号\tbeneficiaryIdCard\tC\tString\tbeneficiaryType为0时填写\n" +
                "受益人身份证是否长期\tbeneficiaryIdCardExtended\tC\tInteger\tbeneficiaryType为0时填写；0-否 1-是\n" +
                "受益人身份证有效期限\tbeneficiaryIdCardExpireDate\tC\tDate\tbeneficiaryType为0时填写，格式：yyyy-MM-hh;如果受益人身份证有效期限为长期，请设置为2099-12-31\n" +
                "受益人企业名称\tbeneficiaryCompanyName\tC\tString\tbeneficiaryType为1时填写\n" +
                "受益人社会信用代码(注册号)\tbeneficiaryRegNo\tC\tString\tbeneficiaryType为1时填写\n" +
                "受益人营业期限是否长期\tbeneficiaryBusinessExtended\tC\tInteger\tbeneficiaryType为1时填写；0-否 1-是\n" +
                "受益人营业有效期限\tbeneficiaryBusinessExpireDate\tC\tDate\tbeneficiaryType为1时填写，格式：yyyy-MM-hh;如果受益人营业有效期限为长期，请设置为2099-12-31\n" +
                "实际控制人类型\tcontrollerType\tC\tInteger\tinControl为0时填写;0-个人 1-企业\n" +
                "实际控制人归属地\tcontrollerArea\tC\tString\tcontrollerType为0时填写\n" +
                "实际控制人姓名\tcontrollerName\tC\tString\tcontrollerType为0时填写\n" +
                "实际控制人身份证号\tcontrollerIdCard\tC\tString\tcontrollerType为0时填写\n" +
                "实际控制人身份证是否长期\tcontrollerIdCardExtended\tC\tInteger\tcontrollerType为0时填写；0-否 1-是\n" +
                "实际控制人身份证有效期限\tcontrollerIdCardExpireDate\tC\tDate\tcontrollerType为0时填写，格式：yyyy-MM-hh;如果实际控制人身份证有效期限为长期，请设置为2099-12-31\n" +
                "实际控制人企业名称\tcontrollerCompanyName\tC\tString\tcontrollerType为1时填写\n" +
                "实际控制人社会信用代码(注册号)\tcontrollerRegNo\tC\tString\tcontrollerType为1时填写\n" +
                "实际控制人营业期限是否长期\tcontrollerBusinessExtended\tC\tInteger\tcontrollerType为1时填写；0-否 1-是\n" +
                "实际控制人营业有效期限\tcontrollerBusinessExpireDate\tC\tDate\tcontrollerType为1时填写，格式：yyyy-MM-hh;如果实际控制人营业有效期限为长期，请设置为2099-12-31\n" +
                "回调通知地址\tnotifyUrl\tO\tString\t开户结果通知，小额打款通知，小额鉴权通知\n" +
                "签名数据\tsignData\tM\tString\t请求签名数据，签名方式见下文验签方式";
        String template = "\"%2$s\":\"\",";
        Arrays.stream(str.split("\n"))
                .filter(StringUtils::isNotBlank)
                .skip(1)
                .forEach(e->{
                    String[] strs = e.split("\t");
                    System.out.println(String.format(template, strs));
                });

    }

    @Test
    public void printMethod(){
        String url = "findBindBankCards";
        String type = "query";
//        url = type+url.substring(0,1).toUpperCase(Locale.ROOT)+url.substring(1);

        String method = "\n/**\n" +
                "     *\n" +
                "     *\n" +
                "     */\n" +
                "    @Override\n" +
                "    public BaoFuResultResp personUnbindCard(PersonUnbindCardReq req) {\n" +
                "        String encryptFields = null;\n" +
                "        String base64Fields = null;\n" +
                "        String signFields = \"\";\n" +
                "        BaoFuResultResp baoFuResultResp = postResultPerson(req, BaoFuPayConstant.PERSON_UNBIND_CARD, encryptFields, base64Fields, signFields);\n" +
                "        return baoFuResultResp;\n" +
                "    }";
        method = method.replaceAll("personUnbindCard", url)
                .replaceAll("PersonUnbindCard", url.substring(0,1).toUpperCase(Locale.ROOT)+url.substring(1))
                .replaceAll("PERSON_UNBIND_CARD", url.toUpperCase())
                .replaceAll("Person", type.substring(0,1).toUpperCase()+type.substring(1));
        System.out.println(method);
    }

    @Test
    public void printTestMethod(){
        String url = "employerUnbindCard";
    //        url = type+url.substring(0,1).toUpperCase(Locale.ROOT)+url.substring(1);

    String method =
        "\n"
            + "    @Test\n"
            + "    public void employerApiOpen() {\n"
            + "    EmployerApiOpenReq req =\n"
            + "        JSON.parseObject(\n"
            + "            \"\",\n"
            + "            EmployerApiOpenReq.class);\n"
            + "        req.setOrgNo(payConfig.getOid_partner());\n"
            + "        req.setTerminalNo(payConfig.getTerminalNo());\n"
            + "        String date = new SimpleDateFormat(\"yyyyMMddHHmmss\").format(new Date());\n"
            + "        req.setRequestDate(date);\n"
            + "\n"
            + "        Object result = service.employerApiOpen(req);\n"
            + "        System.out.println(JSON.toJSONString(result));\n"
            + "    }";
        method = method.replaceAll("employerApiOpen", url)
                .replaceAll("EmployerApiOpen", url.substring(0,1).toUpperCase(Locale.ROOT)+url.substring(1));
        System.out.println(method);
    }
}
